package com.agile.leetcode.jsonpath.readjson;

import cn.hutool.core.collection.CollUtil;

import java.sql.*;
import java.util.List;

/**
 * @author chenzhangkun
 * @ClassName RegionUtil
 * @description: TODO
 * @date 2025年04月27日
 */
public class RegionUtil {
    private static final String URL = "x";
    private static final String USER = "x";
    private static final String PASSWORD = "x";

    public static List<Region> getRegion(){
        String sql="select * from region";
        try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
             PreparedStatement preparedStatement = connection.prepareStatement(sql)) {

            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                List<Region> regionList= CollUtil.newArrayList();
                while (resultSet.next()) {
                    String id = resultSet.getString("id");
                    String name = resultSet.getString("name");
                    String pid = resultSet.getString("pid");
                    Integer level = resultSet.getInt("level");
                    String sname = resultSet.getString("sname");
                    String citycode=resultSet.getString("citycode");
                    String yzcode=resultSet.getString("yzcode");
                    String mername=resultSet.getString("mername");
                    Float lng=resultSet.getFloat("lng");
                    Float lat=resultSet.getFloat("lat");
                    String pinyin=resultSet.getString("pinyin");
                    Region region=new Region(id,name,pid,sname,level,citycode,yzcode,mername,lng,lat,pinyin);
                    regionList.add(region);
                }
                return regionList;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
